package com.tanhua.app.service;

import com.tanhua.api.service.QuestionApi;
import com.tanhua.app.Interceptor.UserHolder;
import com.tanhua.model.pojo.Question;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class QuestionService {

    @DubboReference
    private QuestionApi questionApi;

    // 陌生人问题的更新
    public void questions(String content) {

        // 获取当前用户id
        Long userId = UserHolder.getUserId();

        // 根据用户Id查询问题数据
        Question question = questionApi.findByUserID(userId);

        // 校验
        if (question != null) {
            // 对象存在，更新数据
            question.setTxt(content);

            questionApi.update(question);
        } else {
            // 对象不存在，添加数据
            question = new Question();
            question.setUserId(userId);
            question.setTxt(content);

            questionApi.save(question);
        }
    }
}
